from selenium import webdriver
import time
from unittest import TestCase
import re
from auto_chrome import expt2
from selenium.webdriver.common.by import By




class Testbuy(TestCase):
    def testbuy1(self):
        username = "username"
        passwd = "123456"
        expect = "买入成功!"
        expect2 =expt2.expt1(expt2) - 100

        
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://localhost:90/")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "username").send_keys("lisi")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "password").send_keys("123456")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)
        ele1 = driver.find_element(By.XPATH,'//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/a').click()
        time.sleep(2)
        driver.find_element(By.XPATH,'//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/ul/li[1]/a').click()
        time.sleep(0.3)
        driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[6]/button').click()
        time.sleep(0.3)
        driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/input').send_keys("666666")
        time.sleep(1)
        driver.find_element(By.XPATH,'//*[@id="layui-layer1"]/div[3]/a[1]').click()
        time.sleep(1)
        result = driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[3]/div/div').text


        driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[4]/button').click()

        time.sleep(1)
        driver.quit()
        result2 = expt2.expt1(expt2)

        if result != expect:
            driver.save_screenshot(expect + "--.jpg")
        else:
            print("登陆用例通过！")
        driver.quit()
        self.assertEqual(expect, result)
        self.assertEqual(expect2,result2)


#支付错误

    def testbuy2(self):
        username = "username"
        passwd = "123456"
        expect = "买入失败!"
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://localhost:90/")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "username").send_keys("lisi")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "password").send_keys("123456")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)
        ele1 = driver.find_element(By.XPATH,'//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/a').click()
        time.sleep(2)
        ele1 = driver.find_element(By.XPATH,'//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/ul/li[1]/a').click()
        time.sleep(2)
        ele1 = driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[6]/button').click()
        time.sleep(2)
        ele1 = driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/input').send_keys("666667")
        time.sleep(1)
        ele1 = driver.find_element(By.XPATH,'//*[@id="layui-layer1"]/div[3]/a[1]').click()
        time.sleep(1)
        result = driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[3]/div/div').text
        if result != expect:
            driver.save_screenshot(expect + "--.jpg")
        else:
            print("登陆用例通过！")
        driver.quit()
        self.assertEqual(expect, result)

#银行卡余额不足
    def testbuy3(self):
        username = "username"
        passwd = "123456"
        expect = "买入失败!，银行卡余额不足"
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://localhost:90/")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "username").send_keys("wangwu")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "password").send_keys("123456")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)
        ele1 = driver.find_element(By.XPATH,'//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/a').click()
        time.sleep(2)
        ele1 = driver.find_element(By.XPATH,'//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/ul/li[1]/a').click()
        time.sleep(2)
        ele1 = driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[6]/button').click()
        time.sleep(2)
        ele1 = driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/input').send_keys("666666")
        time.sleep(1)
        ele1 = driver.find_element(By.XPATH,'//*[@id="layui-layer1"]/div[3]/a[1]').click()
        time.sleep(1)
        result = driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[3]/div/div').text
        if result != expect:
            driver.save_screenshot(expect + "--.jpg")
        else:
            print("登陆用例通过！")
        driver.quit()
        self.assertEqual(expect, result)


#没有银行卡
    def testbuy4(self):
        username = "username"
        passwd = "123456"
        expect = "买入失败!，请绑定银行卡"
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://localhost:90/")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "username").send_keys("admin0")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "password").send_keys("123456")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)
        ele1 = driver.find_element(By.XPATH,'//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/a').click()
        time.sleep(2)
        ele1 = driver.find_element(By.XPATH,'//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/ul/li[1]/a').click()
        time.sleep(2)
        ele1 = driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[6]/button').click()
        time.sleep(2)
        ele1 = driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/input').send_keys("666666")
        time.sleep(1)
        ele1 = driver.find_element(By.XPATH,'//*[@id="layui-layer1"]/div[3]/a[1]').click()
        time.sleep(1)
        result = driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[3]/div/div').text
        if result != expect:
            driver.save_screenshot(expect + "--.jpg")
        else:
            print("登陆用例通过！")
        driver.quit()
        self.assertEqual(expect, result)


#基金理财
    def testbuy5(self):
        username = "username"
        passwd = "123456"
        expect = "买入成功!"
        expect2 = expt2.expt1(expt2) - 3000
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://localhost:90/")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "username").send_keys("lisi")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "password").send_keys("123456")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)
        ele1 = driver.find_element(By.XPATH,'//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/a').click()
        time.sleep(2)
        #基金理财
        ele1 = driver.find_element(By.XPATH,'/html/body/div/div/aside/div[2]/nav/ul/li[2]/ul/li[3]/a').click()
        time.sleep(2)
        #投资
        ele1 = driver.find_element(By.XPATH,'/html/body/div[1]/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[9]/button').click()
        time.sleep(5)
        #支付密码
        ele1 = driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/input').send_keys("666666")
        time.sleep(1)
        #确定
        ele1 = driver.find_element(By.XPATH,'/html/body/div[3]/div[3]/a[1]').click()
        time.sleep(1)
        result = driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[3]/div/div').text
        ele1 = driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[4]/button').click()
        driver.quit()

        time.sleep(1)
        result2 = expt2.expt1(expt2)
        if result != expect:
            driver.save_screenshot(expect + "--.jpg")
        else:
            print("登陆用例通过！")

        self.assertEqual(expect, result)
        self.assertEqual(expect2,result2)



#支付失败
    def testbuy6(self):
        username = "username"
        passwd = "123456"
        expect = "买入失败!"
        expect2 = expt2.expt1(expt2)
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://localhost:90/")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "username").send_keys("lisi")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "password").send_keys("123456")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)
        ele1 = driver.find_element(By.XPATH,'//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/a').click()
        time.sleep(2)
        #基金理财
        ele1 = driver.find_element(By.XPATH,'/html/body/div/div/aside/div[2]/nav/ul/li[2]/ul/li[3]/a').click()
        time.sleep(2)
        #投资
        ele1 = driver.find_element(By.XPATH,'/html/body/div[1]/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[9]/button').click()
        time.sleep(2)
        #支付密码
        ele1 = driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/input').send_keys("666667")
        time.sleep(1)
        #确定
        ele1 = driver.find_element(By.XPATH,'/html/body/div[3]/div[3]/a[1]').click()
        time.sleep(1)
        result = driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[3]/div/div').text
        ele1 = driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[4]/button').click()

        time.sleep(1)
        driver.quit()
        result2 = expt2.expt1(expt2)
        if result != expect:
            driver.save_screenshot(expect + "--.jpg")
        else:
            print("登陆用例通过！")
        driver.quit()
        self.assertEqual(expect, result)


#余额不足
    def testbuy7(self):
        username = "username"
        passwd = "123456"
        expect = "买入失败!，银行卡余额不足"
        expect2 = expt2.expt1(expt2)
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://localhost:90/")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "username").send_keys("wangwu")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "password").send_keys("123456")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)
        ele1 = driver.find_element(By.XPATH,'//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/a').click()
        time.sleep(2)
        #基金理财
        ele1 = driver.find_element(By.XPATH,'/html/body/div/div/aside/div[2]/nav/ul/li[2]/ul/li[3]/a').click()
        time.sleep(2)
        #投资
        ele1 = driver.find_element(By.XPATH,'/html/body/div[1]/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[9]/button').click()
        time.sleep(2)
        #支付密码
        ele1 = driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/input').send_keys("666666")
        time.sleep(1)
        #确定
        ele1 = driver.find_element(By.XPATH,'/html/body/div[3]/div[3]/a[1]').click()
        time.sleep(1)
        result = driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[3]/div/div').text
        ele1 = driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[4]/button').click()

        time.sleep(2)
        driver.quit()
        result2 = expt2.expt1(expt2)
        if result != expect:
            driver.save_screenshot(expect + "--.jpg")
        else:
            print("登陆用例通过！")
        driver.quit()
        self.assertEqual(expect, result)
        self.assertEqual(expect2,result2)

#没有银行卡
    def testbuy8(self):
        username = "username"
        passwd = "123456"
        expect = "买入失败!，请绑定银行卡"
        expect2 = "账户余额：0.00元"
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://localhost:90/")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "username").send_keys("admin0")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "password").send_keys("123456")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)
        ele1 = driver.find_element(By.XPATH,'//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/a').click()
        time.sleep(2)
        #基金理财
        ele1 = driver.find_element(By.XPATH,'/html/body/div/div/aside/div[2]/nav/ul/li[2]/ul/li[3]/a').click()
        time.sleep(2)
        #投资
        ele1 = driver.find_element(By.XPATH,'/html/body/div[1]/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[9]/button').click()
        time.sleep(2)
        #支付密码
        ele1 = driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/input').send_keys("666666")
        time.sleep(1)
        #确定
        ele1 = driver.find_element(By.XPATH,'/html/body/div[3]/div[3]/a[1]').click()
        time.sleep(1)
        result = driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[3]/div/div').text
        ele1 = driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[4]/button').click()

        if result != expect:
            driver.save_screenshot(expect + "--.jpg")
        else:
            print("登陆用例通过！")
        driver.quit()
        self.assertEqual(expect, result)

#期限理财
    def testbuy9(self):
        username = "username"
        passwd = "123456"
        expect = "买入成功!"
        expect2 = expt2.expt1(expt2) - 5000
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://localhost:90/")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "username").send_keys("lisi")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "password").send_keys("123456")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)
        ele1 = driver.find_element(By.XPATH,'//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/a').click()
        time.sleep(2)
        #基金理财
        ele1 = driver.find_element(By.XPATH,'/html/body/div/div/aside/div[2]/nav/ul/li[2]/ul/li[2]/a').click()
        time.sleep(2)
        #投资
        ele1 = driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[8]/button').click()
        time.sleep(2)
        #支付密码
        ele1 = driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/input').send_keys("666666")
        time.sleep(1)
        #确定
        ele1 = driver.find_element(By.XPATH,'/html/body/div[3]/div[3]/a[1]').click()
        time.sleep(1)
        result = driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[3]/div/div').text
        ele1 = driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[4]/button').click()

        time.sleep(1)
        driver.quit()
        result2 =expt2.expt1(expt2)
        if result != expect:
            driver.save_screenshot(expect + "--.jpg")
        else:
            print("登陆用例通过！")
        driver.quit()
        self.assertEqual(expect, result)
        self.assertEqual(expect2,result2)


#支付密码错误
    def testbuy10(self):
        username = "username"
        passwd = "123456"
        expect = "买入失败!"
        expect2 = expt2.expt1(expt2)
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://localhost:90/")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "username").send_keys("lisi")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "password").send_keys("123456")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)
        ele1 = driver.find_element(By.XPATH,'//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/a').click()
        time.sleep(2)
        #基金理财
        ele1 = driver.find_element(By.XPATH,'/html/body/div/div/aside/div[2]/nav/ul/li[2]/ul/li[2]/a').click()
        time.sleep(2)
        #投资
        ele1 = driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[8]/button').click()
        time.sleep(2)
        #支付密码
        ele1 = driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/input').send_keys("666667")
        time.sleep(1)
        #确定
        ele1 = driver.find_element(By.XPATH,'/html/body/div[3]/div[3]/a[1]').click()
        time.sleep(1)
        result = driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[3]/div/div').text
        ele1 = driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[4]/button').click()

        time.sleep(1)
        driver.quit()
        result2 = expt2.expt1(expt2)
        if result != expect:
            driver.save_screenshot(expect + "--.jpg")
        else:
            print("登陆用例通过！")
        driver.quit()
        self.assertEqual(expect, result)
        self.assertEqual(expect2,result2)




    #余额不足
    def testbuy11(self):
        def testbuy11(self):
            username = "username"
            passwd = "123456"
            expect = "买入失败!，银行卡余额不足"

            driver = webdriver.Chrome()
            driver.maximize_window()
            driver.get("http://localhost:90/")
            time.sleep(1)
            driver.find_element(By.ID, "username").send_keys("wangwu")
            time.sleep(1)
            driver.find_element(By.ID, "password").send_keys("123456")
            time.sleep(1)
            driver.find_element(By.ID, "login_btn").click()
            time.sleep(1)
            driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/a').click()
            time.sleep(1)
            # 基金理财
            driver.find_element(By.XPATH, '/html/body/div/div/aside/div[2]/nav/ul/li[2]/ul/li[2]/a').click()
            time.sleep(1)
            # 投资
            driver.find_element(By.XPATH,
                                '/html/body/div/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[8]/button').click()

            # 支付密码
            driver.find_element(By.XPATH, '/html/body/div[3]/div[2]/input').send_keys("666666")

            # 确定
            driver.find_element(By.XPATH, '/html/body/div[3]/div[3]/a[1]').click()
            time.sleep(1)
            result = driver.find_element(By.XPATH,
                                         '/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[3]/div/div').text
            # driver.find_element(By.XPATH, '/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[4]/button').click()

            driver.quit()

            # if result != expect:
            #     driver.save_screenshot(expect + "--.jpg")
            # else:
            #     print("登陆用例通过！")
            driver.quit()
            self.assertEqual(expect, result)




    #没有银行卡
    def testbuy12(self):
        username = "username"
        passwd = "123456"
        expect = "买入失败!，请绑定银行卡"
        expect2 = "账户余额：0.00元"
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://localhost:90/")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "username").send_keys("admin0")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "password").send_keys("123456")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)
        ele1 = driver.find_element(By.XPATH,'/html/body/div[1]/div/aside/div[2]/nav/ul/li[2]/a').click()
        time.sleep(2)
        #基金理财
        ele1 = driver.find_element(By.XPATH,'/html/body/div/div/aside/div[2]/nav/ul/li[2]/ul/li[2]/a').click()
        time.sleep(2)
        #投资
        ele1 = driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[8]/button').click()
        time.sleep(2)
        #支付密码
        ele1 = driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/input').send_keys("666666")
        time.sleep(1)
        #确定
        ele1 = driver.find_element(By.XPATH,'/html/body/div[3]/div[3]/a[1]').click()
        time.sleep(1)
        result = driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[3]/div/div').text
        ele1 = driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[4]/button').click()

        if result != expect:
            driver.save_screenshot(expect + "--.jpg")
        else:
            print("登陆用例通过！")
        driver.quit()
        self.assertEqual(expect, result)






